package com.yida.controller;

import com.yida.bean.comment;
import com.yida.service.serverblog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Controller
public class about {

	@Autowired
	public serverblog service;
	
	@RequestMapping("/about") 
	public String index(Model mode,Integer page) {

	    List<comment> listcomment =     service.leavecomment();
		mode.addAttribute("comments", listcomment);
		return "about";
	}
	
	@RequestMapping("/about/comments")
	public String comments(Model mode,Integer id) {
		  List<comment> listcomment =     service.leavecomment();
		  mode.addAttribute("comments", listcomment);
		return "about :: commentList"; 
	}
	

	@RequestMapping("/about/post")
	public String post(comment comment,HttpSession session,String email) {
		int replyid = comment.getReplyid();
		if (replyid == -1) {
			comment.setReplyid(null);
		}	
		//设置时间
		Date date = new Date();
		comment.setConmmentDate(new Timestamp(date.getTime()));
        //插入
        Integer pdInteger = service.saveConmment(comment,session,2,null, email);
     System.out.print(email);
		return "redirect:/about/comments";
	}
	
	
	
	
}

